<?php

$p_login = (!empty($_POST['txt_login'])) ? htmlEntities($_POST['txt_login'], ENT_QUOTES) : '';

//$p_pass = (!empty($_POST['txt_pass'])) ? md5($_POST['txt_pass']) : '';

$p_pass = (!empty($_POST['txt_pass'])) ? $_POST['txt_pass'] : '';

$msj_usuario = '';

if (!empty($p_login) && !empty($p_pass)){
    
    require_once 'clases/Login.class.php';
    
    $login = new Login($p_login, $p_pass);

    $login_valido = $login->validaLogin();
    
    print_r($login_valido);
    
    if (is_array($login_valido) && count($login_valido) > 0){
        
        if ($login_valido[0]['cantidad'] == 1){
        
            $login->creaSesion();

            header('Location: scripts/home.php');

        }
        else{
            
            $msj_usuario = 'Usuario o contrase&ntilde;a inv&aacute;lido.';
            
        }

        
    }

}

?>

<!DOCTYPE html>
<html>
    <head>
        <title></title>
    </head>
    
    <body>
        <div id="login_wrap">
            
            <div>
                
                <span><?php echo $msj_usuario; ?></span>
                
                <form id="frm_login" method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
                    <label for="txt_login">Usuario: </label>
                    <input type="text" id="txt_login" name="txt_login" maxlength="15" size="15" placeholder="Usuario">
                    
                    <br />
                    
                    <label for="txt_pass">Contrase&ntilde;a: </label>
                    <input type="password" id="txt_pass" name="txt_pass" maxlength="15" size="15" placeholder="Contrase&ntilde;a">
                    
                    <br />
                    
                    <input type="submit" id="btn_aceptar" name="btn_aceptar" value="Aceptar">
                    
                </form>
            </div>
            
        </div>
    </body>
</html>